import 'package:dio/dio.dart';
import 'package:eplorex/models/message/chat_message_type.dart' as types;
import 'package:eplorex/utils/HttpUtil.dart';

import '../models/user/user.dart';

const USER_URL = 'http://rap2api.taobao.org/app/mock/318423/api/user/info';

class UserInfoDao {
  static Future<types.User?> fetch(num uid) async {

    Response? response =
        await HttpUtil.getInstance().post('/api/user/get', data: [uid]);
    if (response!.statusCode == 200 && response.data['data'] != null) {
      var tmp = response.data['data'] as List;
      if (tmp.isNotEmpty) {
        return User.fromJson({
          'uid': tmp[0]['userId'].toString(),
          'firstName': tmp[0]['userName'],
          'imageUrl': tmp[0]['avatar']
        });
      } else {
        return null;
      }
    } else {
      throw Exception('Failed to load home_page.json');
    }
  }
}
